package com.mzba.zxdlyllp;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import cn.waps.AppConnect;

/**
 * 
 * @author 06peng
 *
 */
public class SplashActivity extends BasicActivity {
	
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
	//设置界面跳转时间为5秒
	int time = 3;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		String PREFS_NAME = "preferences";
		String FIRST_RUN_TAG = "first_run";
		SharedPreferences localSharedPreferences = getSharedPreferences(PREFS_NAME, Activity.MODE_PRIVATE);
		if (localSharedPreferences.getBoolean(FIRST_RUN_TAG, false)) {
			AppConnect.getInstance(this);
			// 初始化插屏广告数据
	    	AppConnect.getInstance(this).initPopAd(this);
	    	// 开屏广告
	    	View loadingAdView = LoadingPopAd.getInstance().getContentView(this, time);
			if (loadingAdView != null) {
				// 将开屏广告的布局View设置到当前Activity的整体布局中
				this.setContentView(loadingAdView);
			}
	    	//设置延时跳转到主界面
	    	scheduler.schedule(new Runnable(){
				@Override
				public void run() {
					Intent intent = new Intent(SplashActivity.this, MainActivity.class);
					SplashActivity.this.startActivity(intent);
					SplashActivity.this.finish();
					AppConnect.getInstance(SplashActivity.this).finalize(); 
				}
	    	}, time, TimeUnit.SECONDS);
		} else {
			Intent intent = new Intent(SplashActivity.this, MainActivity.class);
			SplashActivity.this.startActivity(intent);
			SplashActivity.this.finish();
		}
	}
	
	@Override
	protected void onDestroy() {
		AppConnect.getInstance(this).finalize();
		super.onDestroy();
	}
}
